#!/usr/bin/python
# Package Deploy Module v0.01
# by William Edwards 07-28-09
# 
# This module is designed for the deployment of packages to remote machines.

# This function displays the options for either deploying to a single
# machine or multiple machines.
def menu_top():
	choice = "0"
	print "Select an option: "
	print " 1 - Deploy package(s) to a single machine"
	print " 2 - Deploy package(s) multiple machines"
	print " q - Quit"
	choice = str(raw_input("Choice: "))
	while choice != "q":
		if choice == "1":
			deploy_single()
		elif choice == "2":
			deploy_multiple()

# This function displays the menu options for deploying single or multiple
# packages to a single remote machine.
def menu_single():
	choice = "0"
	print "Select an option: "
	print " 1 - Deploy a single *.deb package"  # Displays the options to the user
	print " 2 - Deploy multiple *.deb packages"
	print " q - Quit"
	choice = str(raw_input("Choice: ")) # Gets the menu choice from the user
	while choice != "q": # The loop will quit if "q" is chosen.
		if choice == "1":
			print "Enter the local path of the *.deb package"
			path = str(raw_input("Path: ")) # Gets the package path from user
			print ''
			print "Enter the IP Address or hostname of the remote machine"
			ip = str(raw_input("IP: ")) # Gets the remote computer's IP or hostname
			print ''
			print "Enter the username"
			username = str(raw_input("Username: ")) # Gets the root username
			print ''
			print "Enter the password"
			password = getpass.getpass() # This uses getpass so the password is not shown in plain text in the console.
			deploy_install(path, ip, username, password)
			print ''
			print 'Installing selected package ' + path + '...'
			print ''
			choice = "q"
		elif choice =="2": # If 2 is chosen, it will deploy multiple packages to a single machine
			print "Enter the local path of the folder that contains the *.deb files"
			path = str(raw_input("Path: "))
			path = path + '/*.deb'
			print ''
			print "Enter the IP Address or hostname of the remote machine"
			ip = str(raw_input("IP: "))
			print ''
			print "Enter the username"
			username = str(raw_input("Username: "))
			print ''
			print "Enter the password"
			password = getpass.getpass() # This uses getpass so the password is not shown in plain text in the console.
			deploy_install(path, ip, username, password)
			print ''
			print 'Installing selected packages in ' + path + '...'
			print ''
			choice = "q"


